import * as echarts from "echarts";

export default function useEcharts(el) {
  // 1. echart 实例
  const echartsInstance = echarts.init(el, "", { renderer: "canvas" });

  // 2.设置实例化参数
  const setOptions = (options) => {
    echartsInstance.setOption(options);
  };

  // 3.更新尺寸
  const updateSize = () => {
    echartsInstance.resize();
  };

  window.addEventListener("resize", () => {
    setTimeout(() => {
      echartsInstance.resize();
    }, 1000);
  });

  return { echartsInstance, setOptions, updateSize };
}
